import sys
import logging
from logging.handlers import RotatingFileHandler
logging.basicConfig(filename='output_and_error_log.log', level=logging.DEBUG,
                    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# logger = logging.getLogger("process_ck")
# LEVEL = logging.DEBUG
#
# handler = RotatingFileHandler("logs/output_log.log", maxBytes=1_000_000_000, backupCount=1000)
#
# formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
# handler.setFormatter(formatter)
# logger.addHandler(handler)
# logger.setLevel(LEVEL)
# class OutputCapture:
#     def write(self, message):
#         # 记录输出信息到日志
#         logging.info(message.strip())
#
# class ErrorCapture:
#     def write(self, message):
#         # 记录错误信息到日志
#         logging.error(message.strip())
#
# # 创建输出和错误捕获器
# output_capturer = OutputCapture()
# error_capturer = ErrorCapture()
#
# # 保存原始的sys.stdout和sys.stderr
# original_stdout = sys.stdout
# original_stderr = sys.stderr
#
# # 重定向输出和错误流
# sys.stdout = output_capturer
# sys.stderr = error_capturer

